﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ShoppingLists.Core
{
    public class ShoppingListPresenter
    {
        public PredefinedProductsList predefinedProductsList { get; private set; }
        public Dictionary<string, ShoppingList> shoppingLists { get; private set; }

        public ShoppingListPresenter()
        {
            predefinedProductsList = new PredefinedProductsList(); //deserialization for example to fill it out
            shoppingLists = new Dictionary<string, ShoppingList>(); // deserialization for example to fill it out
        }

        public void addProduct(String product)
        {
            predefinedProductsList.addProduct(product);
        }

        public void removeProduct(String product)
        {
            predefinedProductsList.removeProduct(product);
        }

        public int numberOfProducts()
        {
            return predefinedProductsList.numberOfProducts();
        }

        public void createShoppingList(String shoppingList)
        {
            ShoppingList newShoppingList = new ShoppingList();
            shoppingLists.Add(shoppingList, newShoppingList);
        }

        public void addProduct(String product, String shoppingList)
        {
            if (!shoppingLists.ContainsKey(shoppingList))
            {
                shoppingLists.Add(shoppingList, new ShoppingList());
            }
   
            shoppingLists[shoppingList].addProduct(product);

            if (!predefinedProductsList.Products.Where(x => x.ProductName == product).Any())
            {
                predefinedProductsList.addProduct(product);
            }
        }

        public void removeProduct(String product, String shoppingList)
        {
            shoppingLists[shoppingList].removeProduct(product);
        }

        public int numberOfProducts(String shoppingList)
        {
            return shoppingLists[shoppingList].numberOfProducts();
        }

    }
}
